<template>
	<view class="content" :style="{background: `url(${imgPath}storage/home/home_bg.png)`,backgroundSize: '100%'}">
		<view class="box">
			<view class="goods">
				<view class="img">
					<u--image :showLoading="true" :src="info.product_img" width="180rpx" height="180rpx"></u--image>
				</view>
				<view class="text">
					<view class="top">
						{{info.product_name}}
					</view>
					<view class="bottom">
						X 1
					</view>
				</view>
				<view class="num">
					¥{{info.price}}
				</view>
			</view>
			<view class="information">
				<view class="title">
					收货人信息
				</view>
				<view class="information-box">
					<view class="item">
						<view class="lable">
							收货人：
						</view>
						<view class="text">
							{{info.address.name}}
						</view>
					</view>
					<view class="item">
						<view class="lable">
							联系电话：
						</view>
						<view class="text">
							{{info.address.mobile}}
						</view>
					</view>
					<view class="item">
						<view class="lable">
							详细地址：
						</view>
						<view class="text">
							{{info.address.address + info.address.detail_address}}
						</view>
					</view>
				</view>
			</view>
			<view class="order">
				<view class="title">
					订单信息
				</view>
				<view class="order-box">
					<view class="item">
						<view class="lable">
							合计金额：
						</view>
						<view class="text">
							{{info.price}}
						</view>
					</view>
					<view class="item">
						<view class="lable">
							订单编号：
						</view>
						<view class="text">
							{{info.order_no}}
						</view>
						<u-icon name="file-text" color="#EA6F29" @click="replication(info.order_no)"></u-icon>
					</view>
					<view class="item">
						<view class="lable">
							创建时间：
						</view>
						<view class="text">
							{{info.create_time}}
						</view>
					</view>
					<view class="item">
						<view class="lable">
							支付时间：
						</view>
						<view class="text">
							{{info.pay_time || ''}}
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="button-box">
			<view class="left">
				合计：¥{{info.price}}
			</view>
			<view class="right">
				<view class="left-btn" @click="delOrder(info.order_id)" v-if="info.status == 3">
					删除记录
				</view>
				<view class="left-btn" @click="cancelOrder(info.order_id)" v-if="info.status == 1">
					取消订单
				</view>
				<view class="right-btn" @click="payOrder(info.order_id)" v-if="info.status == 1">
					去支付
				</view>
				<view class="right-btn" @click="buyAgain(info)" v-if="info.status == 2 || info.status == 3">
					再次购买
				</view>
			</view>
		</view>
		<uni-popup ref="popup" type="center">
			<view class="pay-popup">
				<view class="close" @click="close">
					<u-icon name="close" color="#fff" size="28" bold></u-icon>
				</view>
				<view class="successful-img">
					<u--image :showLoading="true" :src="imgPath + 'storage/home/paysuccessful.png'" width="192rpx"
						height="40rpx"></u--image>
				</view>
				<view class="popup-box" :style="{background: `url(${imgPath}storage/home/paybg.png)`,backgroundSize: '100%'}">
					<view class="ok-img">
						<u--image :showLoading="true" :src="imgPath + 'storage/home/payok.png'" width="150rpx"
							height="152rpx"></u--image>
					</view>
					<view class="text">
						您已成功支付，可到个人中心查看！
					</view>
					<view class="btns">
						<view class="left-btn" @click="goHome">
							返回首页
						</view>
						<view class="right-btn" @click="showDetail">
							查看订单
						</view>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		pay
	} from '@/utils/index.js'
	export default {
		data() {
			return {
				imgPath: this.$store.state.user.baseURL,
				info: {},
				id: ''
			}
		},
		onLoad(e) {
			this.id = e.id
			this.getInfo()
		},
		methods: {
			getInfo(){
				this.$api.productOrderinfo({order_id:this.id}).then(res =>{
					this.info = res.data
				})
			},
			replication(text) {
				uni.setClipboardData({
					data: text,
					success: function() {
						console.log('复制成功');
					}
				});
			},
			payOrder(id) {
				pay(id, 3, (() => {
					this.getInfo(id)
					this.open()
				}))
			},
			cancelOrder(order_id) {
				this.$api.productOrdercancel({order_id}).then(res => {
					this.getInfo()
				})
			},
			delOrder(order_id) {
				this.$api.productOrderdel({order_id}).then(res => {
					let pages = getCurrentPages()
					let prevPage = pages[pages.length - 2]
					if(prevPage.$vm.updata != undefined) prevPage.$vm.updata()
					uni.navigateBack({
						delta: 1
					})
				})
			},
			buyAgain(obj) {
				console.log(obj);
				this.$api.productOrdercreate({
					product_id: obj.product_id,
					remark: obj.remark,
					address_id: obj.address_id
				}).then(res => {
					 pay(res.data.order_id,3)
				})
			},
			close() {
				this.$refs.popup.close()
			},
			open() {
				this.$refs.popup.open()
			},
			goHome(){
				this.close()
				uni.switchTab({
					url: '/pages/index/index'
				})
			},
			showDetail(){
				this.close()
			}
		}
	}
</script>

<style scoped lang="scss">
	.content {
		min-height: 100vh;
		z-index: -1;
	}
	.box{
		padding: 20rpx 30rpx 0 30rpx;
	}
	.goods,
	.information,
	.order{
		background: #FEF1DC;
		border-radius: 20rpx;
		margin-bottom: 16rpx;
		box-sizing: border-box;
	}
	.goods{
		height: 260rpx;
		display: flex;
		padding: 40rpx 30rpx;
		.img{
			width: 180rpx;
			height: 180rpx;
		}
		.text{
			flex: 1;
			padding: 0 0 0 10rpx;
			.top{
				font-family: PingFangSC, PingFang SC;
				font-weight: 500;
				font-size: 28rpx;
				color: #111111;
				line-height: 40rpx;
				text-align: left;
				font-style: normal;
			}
			.bottom{
				padding-top: 10rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				font-size: 24rpx;
				color: #AAAAAA;
				line-height: 34rpx;
				text-align: left;
				font-style: normal;
			}
		}
		.num{
			width: 150rpx;
			font-family: PingFangSC, PingFang SC;
			font-weight: 600;
			font-size: 36rpx;
			color: #D06122;
			line-height: 180rpx;
			text-align: right;
			font-style: normal;
		}
	}
	.information{
		height: 284rpx;
		padding: 30rpx;
		.title{
			font-family: PingFangSC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #111111;
			line-height: 40rpx;
			text-align: left;
			font-style: normal;
		}
		.information-box{
			padding-top: 30rpx;
			.item{
				display: flex;
				padding-bottom: 16rpx;
				.lable{
					width: 180rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #999999;
					line-height: 34rpx;
					text-align: left;
					font-style: normal;
				}
				.text{
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #111111;
					line-height: 34rpx;
					text-align: left;
					font-style: normal;
				}
			}
		}
	}
	.order{
		height: 330rpx;
		padding: 30rpx;
		.title{
			font-family: PingFangSC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #111111;
			line-height: 40rpx;
			text-align: left;
			font-style: normal;
		}
		.order-box{
			padding-top: 30rpx;
			.item{
				display: flex;
				padding-bottom: 16rpx;
				.lable{
					width: 180rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #999999;
					line-height: 34rpx;
					text-align: left;
					font-style: normal;
				}
				.text{
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #111111;
					line-height: 34rpx;
					text-align: left;
					font-style: normal;
				}
			}
		}
	}
	.button-box {
		box-sizing: border-box;
		position: absolute;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 124rpx;
		background: #FEF1DC;
		padding: 0 30rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
	
		.left {
			font-family: PingFangSC, PingFang SC;
			font-weight: 600;
			font-size: 30rpx;
			color: #6A2D0A;
			line-height: 42rpx;
			text-align: left;
			font-style: normal;
		}
	
		.right {
			display: flex;
	
			.left-btn,
			.right-btn {
				width: 220rpx;
				height: 84rpx;
				border-radius: 42rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 500;
				font-size: 30rpx;
				line-height: 84rpx;
				text-align: center;
				font-style: normal;
			}
	
			.left-btn {
				color: #D06122;
				border: 2rpx solid #D06122;
			}
	
			.right-btn {
				color: #FFFFFF;
				margin-left: 20rpx;
				background: linear-gradient(270deg, #EA6F29 0%, #FAAA7D 100%);
			}
		}
	}
	.pay-popup {
		width: 570rpx;
		height: 636rpx;
		background: linear-gradient(270deg, #FFFFFF 0%, #F2D8AE 100%);
		border-radius: 40rpx;
		box-sizing: border-box;
		.close {
			width: 90rpx;
			height: 90rpx;
			position: absolute;
			bottom: -150rpx;
			left: 50%;
			transform: translateX(-50%);
			border: 8rpx solid white;
			border-radius: 50%;
			display: flex;
			justify-content: center;
			align-items: center;
		}
		.successful-img {
			height: 120rpx;
			display: flex;
			justify-content: center;
			align-items: center;
		}
	
		.popup-box {
			width: 570rpx;
			height: 516rpx;
			background-size: 100% 100%;
			display: flex;
			flex-direction: column;
			align-items: center;
			.ok-img{
				padding-top: 56rpx;
			}
			.text{
				font-family: PingFangSC, PingFang SC;
				font-weight: 500;
				font-size: 28rpx;
				color: #999999;
				line-height: 40rpx;
				text-align: left;
				font-style: normal;
				padding-top: 44rpx;
			}
			.btns{
				padding-top: 80rpx;
				display: flex;
				justify-content: space-between;
				width: 450rpx;
				.left-btn{
					width: 200rpx;
					height: 84rpx;
					background: #A3A3A3;
					border-radius: 16rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 500;
					font-size: 30rpx;
					color: #FFFFFF;
					line-height: 84rpx;
					text-align: center;
					font-style: normal;
				}
				.right-btn{
					width: 200rpx;
					height: 84rpx;
					background: linear-gradient( 270deg, #EA6F29 0%, #FAAA7D 100%);
					border-radius: 16rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 500;
					font-size: 30rpx;
					color: #FFFFFF;
					line-height: 84rpx;
					text-align: center;
					font-style: normal;
				}
			}
		}
	}
</style>
